<?php

/*
 * Built by :
 * Andi Kurniawan (fandikurniawan89@gmail.com) at system analis
 * Alfian Tinangon (alfian.tinangon@gmail.com) at user interface and programming
 */

class Mahasiswa extends CI_Controller {

    function __construct() {
        parent::__construct();
        $login = $this->session->userdata('login');
        $privilege = $this->session->userdata('pri');
        if ($login != TRUE || $privilege != 3) {
            redirect('main/logout');
        }
    }

    function index() {
        redirect('mahasiswa/beranda');
    }

    function beranda() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['stat'] = $this->mmr->stat($nim);
        $data['menu'] = $this->mmr->menu_surat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->infoMhs()) {
            $dgh = $this->mmr->infoMhs();
            $ta['info'] = $dgh->info;
            $ta['by'] = $dgh->set;
        } else {
            $ta['info'] = 'Tidak ada info';
            $ta['by'] = 'system';
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/notif', $ta);
        $this->load->view('mhs/footer');
    }

    function bimbingan() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->log_judul($nim)) {
            $data['judul'] = $this->mmr->log_judul($nim);
        } else {
            $data['judul'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/bimbingan', $data);
        $this->load->view('mhs/footer');
    }

    function judul() {
        $nim = $this->session->userdata('username');
        $date = gmdate('Y-m-d-H:i:s');
        $id = $nim . $date;
        $input = array(
            'id' => $this->encrypt->sha1($id),
            'nim' => $this->session->userdata('username'),
            'judul_1' => $this->input->post('judul1'),
            'judul_2' => $this->input->post('judul2'),
            'subyek' => $this->input->post('subyek'),
            'keyword' => $this->input->post('keyword'),
            'submit' => gmdate('Y-m-d H:i:s')
        );
        $this->mmr->judul($input);
        if ($this->mmr->email_mhs($nim)) {
            $da = $this->mmr->email_mhs($nim);
        } else {
            $da = NULL;
        }
        $email = $da->email;
        $this->load->library('email');
        $this->email->clear();
        $this->email->to($email);
        $this->email->from('noreply@andikurniawan.com');
        $this->email->subject('Pendaftaran judul proposal.');
        $this->email->message('Anda telah mengajukan judul proposal dan telah kami terima, Terima kasih.');
        $this->email->send();
        redirect('mahasiswa/submit');
    }

    function submit() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $alert['alert'] = '<div class="alert alert-info"><strong>Judul anda sudah terkirim!</strong> Silahkan tunggu informasi selanjutnya.</div>';
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/alert', $alert);
        $this->load->view('mhs/footer');
    }

    function tesis() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->tesis($nim)) {
            $data['tesis'] = $this->mmr->tesis($nim);
        } else {
            $data['tesis'] = array();
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/tesis', $data);
        $this->load->view('mhs/footer');
    }

    //mengenai surat
    //start
    function surat() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $cek = $this->mmr->cek_surat($nim);
        if ($cek > 0) {
            $alert['alert'] = '<div class="alert alert-info"><strong>Surat anda sudah kami terima !</strong> Silahkan ambil di ruangan kajur 1 x 24 jam setelah pengajuan.</div>';
            $data['menu'] = $this->mmr->menu_surat($nim);
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimpro($nim)) {
                $data['bimpro'] = $this->mmr->bimpro($nim);
            } else {
                $data['bimpro'] = FALSE;
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            $this->parser->parse('mhs/header', $na);
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->parser->parse('mhs/alert', $alert);
            $this->load->view('mhs/footer');
        } else {
            if ($this->mmr->surat($nim)) {
                $data['surat'] = $this->mmr->surat($nim);
            } else {
                $data['surat'] = array();
            }
            $data['menu'] = $this->mmr->menu_surat($nim);
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimpro($nim)) {
                $data['bimpro'] = $this->mmr->bimpro($nim);
            } else {
                $data['bimpro'] = FALSE;
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            if ($this->mmr->tesis($nim)) {
                $data['tesis'] = $this->mmr->tesis($nim);
            } else {
                $data['tesis'] = array();
            }
            $this->parser->parse('mhs/header', $na);
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->load->view('mhs/surat', $data);
            $this->load->view('mhs/footer');
        }
    }

    function letter() {
        $input = array(
            'id' => $this->input->post('id'),
            'subyek' => $this->input->post('subyek'),
            'lokasi' => $this->input->post('lokasi')
        );
        $this->mmr->let($input);
        redirect('mahasiswa/surat');
    }

    //end surat

    function saran() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        if ($this->mmr->log_judul($nim)) {
            $data['judul'] = $this->mmr->log_judul($nim);
        } else {
            $data['judul'] = array();
        }
        $saran_id = $this->uri->segment(3);
        $da = $this->mmr->saran_judul($saran_id);
        $dat['saran'] = $da->saran;
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/view-saran', $dat);
        $this->load->view('mhs/footer');
    }

    //start bimbingan proposal
    function bimbingan_proposal() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        if ($this->mmr->get_id_tesis($nim)) {
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = $da->id;
            $kode = array('kode' => $da->id);
            $this->session->set_userdata($kode);
        } else {
            $da = array();
            $dat['kode'] = NULL;
            $kode = array('kode' => $da);
            $this->session->set_userdata($kode);
        }
        $dat['error'] = '';
        if ($this->mmr->bimbingan_proposal($nim)) {
            $dat['tesis'] = $this->mmr->bimbingan_proposal($nim);
        } else {
            $dat['tesis'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/bimbingan-proposal', $dat);
        $this->load->view('mhs/footer');
    }

    function bimbingan_upload() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|docx|rar';
        $config['max_size'] = '10000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $nim = $this->session->userdata('username');
            $nm = $this->mmr->get_nama($nim);
            $na['nama'] = $nm->nama;
            $na['nim'] = $nm->nim;
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = $da->id;
            $dat['error'] = array('error' => $this->upload->display_errors());
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimpro($nim)) {
                $data['bimpro'] = $this->mmr->bimpro($nim);
            } else {
                $data['bimpro'] = FALSE;
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            if ($this->mmr->tesis($nim)) {
                $data['tesis'] = $this->mmr->tesis($nim);
            } else {
                $data['tesis'] = array();
            }
            $data['menu'] = $this->mmr->menu_surat($nim);
            $data['stat'] = $this->mmr->stat($nim);
            $this->parser->parse('mhs/header', $na);
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->parser->parse('mhs/bimbingan-proposal', $dat);
            $this->load->view('mhs/footer');
        } else {
            $file = $this->upload->data();
            $input = array(
                'hash' => $this->encrypt->sha1($file['file_name']),
                'bab' => $this->input->post('bab'),
                'kode' => $this->input->post('kode'),
                'file_name' => $file['file_name'],
                'full_path' => base_url() . 'uploads/' . $file['file_name'],
                'file_ext' => $file['file_ext'],
                'file_size' => $file['file_size'],
                'time' => gmdate('Y-m-d'),
                'uploader' => $this->session->userdata('username')
            );
            $this->mmr->insert_upload($input);
            $nim = $this->session->userdata('username');
            $nm = $this->mmr->get_nama($nim);
            $na['nama'] = $nm->nama;
            $na['nim'] = $nm->nim;
            /* em */
//            $id = $this->session->userdata('kode');
//            $em = $this->mmr->mail_pemb($id);
//            $em1 = $em->em1;
//            $em2 = $em->em2;
//            $this->load->library('email');
//            $this->email->clear();
//            $this->email->to(array($em1, $em2));
//            $this->email->from('noreply@andikurniawan.com');
//            $this->email->subject('Bimbingan Proposal Tesis.');
//            $this->email->message('Mahasiswa Bimbingan anda mengirim file bimbingan ' . $this->input->post('bab') . '. Silahkan cek di web. Terima kasih.');
//            $this->email->send();
            $this->session->unset_userdata('kode');
            /* End em */
            $alert['alert'] = '<div class="alert alert-info"><strong>File berhasil dikirim!</strong></div>';
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            if ($this->mmr->bimpro($nim)) {
                $data['bimpro'] = $this->mmr->bimpro($nim);
            } else {
                $data['bimpro'] = FALSE;
            }
            if ($this->mmr->tesis($nim)) {
                $data['tesis'] = $this->mmr->tesis($nim);
            } else {
                $data['tesis'] = array();
            }
            $data['menu'] = $this->mmr->menu_surat($nim);
            $data['stat'] = $this->mmr->stat($nim);
            $this->parser->parse('mhs/header', $na);
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->parser->parse('mhs/alert', $alert);
            $this->load->view('mhs/footer');
        }
    }

    //end bimbingan proposal
    //start bimbingan tesis

    function bimbingan_tesis() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        if ($this->mmr->get_id_tesis($nim)) {
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = $da->id;
        } else {
            $dat['kode'] = NULL;
        }
        $dat['error'] = '';
        if ($this->mmr->bimbingan_tesis($nim)) {
            $dat['tesis'] = $this->mmr->bimbingan_tesis($nim);
        } else {
            $dat['tesis'] = array();
        }
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/bimbingan-tesis', $dat);
        $this->load->view('mhs/footer');
    }

    function bimbingan_tesis_upload() {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|docx|rar';
        $config['max_size'] = '10000';
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload()) {
            $nim = $this->session->userdata('username');
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = $da->id;
            $dat['error'] = array('error' => $this->upload->display_errors());
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            $data['menu'] = $this->mmr->menu_surat($nim);
            $data['stat'] = $this->mmr->stat($nim);
            $this->load->view('mhs/header');
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->parser->parse('mhs/bimbingan-proposal', $dat);
            $this->load->view('mhs/footer');
        } else {
            $file = $this->upload->data();
            $input = array(
                'hash' => $this->encrypt->sha1($file['file_name']),
                'bab' => $this->input->post('bab'),
                'kode' => $this->input->post('kode'),
                'file_name' => $file['file_name'],
                'full_path' => base_url() . 'uploads/' . $file['file_name'],
                'file_ext' => $file['file_ext'],
                'file_size' => $file['file_size'],
                'tipe' => 'Tesis',
                'time' => gmdate('Y-m-d'),
                'uploader' => $this->session->userdata('username')
            );
            $this->mmr->insert_upload($input);
            $nim = $this->session->userdata('username');
            $nm = $this->mmr->get_nama($nim);
            $na['nama'] = $nm->nama;
            $na['nim'] = $nm->nim;
            $alert['alert'] = '<div class="alert alert-info"><strong>File berhasil dikirim!</strong></div>';
            if ($this->mmr->menu_profil($nim)) {
                $data['profil'] = $this->mmr->menu_profil($nim);
            } else {
                $data['profil'] = array();
            }
            if ($this->mmr->bimpro($nim)) {
                $data['bimpro'] = $this->mmr->bimpro($nim);
            } else {
                $data['bimpro'] = FALSE;
            }
            if ($this->mmr->bimtes($nim)) {
                $data['bimtes'] = $this->mmr->bimtes($nim);
            } else {
                $data['bimtes'] = FALSE;
            }
            $data['menu'] = $this->mmr->menu_surat($nim);
            $data['stat'] = $this->mmr->stat($nim);
            $this->parser->parse('mhs/header', $na);
            $this->load->view('mhs/nav-bar');
            $this->load->view('mhs/sidebar', $data);
            $this->parser->parse('mhs/alert', $alert);
            $this->load->view('mhs/footer');
        }
    }

    //end bimbingan tesis

    function download() {
        $this->load->helper('download');
        $id = $this->uri->segment(4);
        $user = $this->session->userdata('username');
        $path = $this->mmr->get_link($id);
        $data = file_get_contents($path->full_path); // Read the file's contents
        $name = $path->file_name;
        force_download($name, $data);
        redirect('mahasiswa/bimbingan_proposal');
    }

    function message() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $id = $this->uri->segment(4);
//        $df = array('jump' => $id);
//        $this->session->set_userdata($df);
        $da = $this->mmr->proposal_saran_log($id);
        if ($this->mmr->proposal_saran_log($id)) {
            $dat['saran'] = $da->saran;
        } else {
            $dat['saran'] = 'Dosen belum / tidak memberikan saran';
        }
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/proposal-saran', $dat);
        $this->load->view('mhs/footer');
    }

    function history() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        if ($this->mmr->get_id_tesis($nim)) {
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = $da->id;
        } else {
            $da = $this->mmr->get_id_tesis($nim);
            $dat['kode'] = NULL;
        }
        $dat['error'] = '';
        if ($this->mmr->log_bimbingan($nim)) {
            $dat['tesis'] = $this->mmr->log_bimbingan($nim);
        } else {
            $dat['tesis'] = array();
        }
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->parser->parse('mhs/history', $dat);
        $this->load->view('mhs/footer');
    }

    function seminar_proposal() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->get_seminar_proposal($nim)) {
            $data['seminar'] = $this->mmr->get_seminar_proposal($nim);
        } else {
            $data['seminar'] = array();
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/seminar', $data);
        $this->load->view('mhs/footer');
    }

    function seminar_tesis() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->get_seminar_tesis($nim)) {
            $data['seminar'] = $this->mmr->get_seminar_tesis($nim);
        } else {
            $data['seminar'] = array();
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/seminar_tes', $data);
        $this->load->view('mhs/footer');
    }

    function seminar_hasil() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        if ($this->mmr->cek_semhas($nim)) {
            $data['cek'] = $this->mmr->cek_semhas($nim);
        } else {
            $data['cek'] = array();
        }
        if ($this->mmr->get_seminar_hasil($nim)) {
            $data['seminar'] = $this->mmr->get_seminar_hasil($nim);
        } else {
            $data['seminar'] = array();
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/sem_hasil', $data);
        $this->load->view('mhs/footer');
    }

    function semHas() {
        $id = $this->uri->segment(3);
        $data = array(
            'id' => $this->encrypt->sha1($id . $this->input->ip_address() . gmdate('Y-m-d H"m:i')),
            'nim' => $id,
            'type' => 'Hasil'
        );
        $this->mmr->semHas($data);
        redirect('mahasiswa/seminar_hasil');
    }

    function password() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/password', $data);
        $this->load->view('mhs/footer');
    }

    function passNew() {
        $id = $this->session->userdata('username');
        $update = array(
            'password' => $this->encrypt->sha1($this->input->post('pass'))
        );
        $this->mmr->updatePass($id, $update);
        redirect('mahasiswa/passSuc');
    }

    function passSuc() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/passSuc', $data);
        $this->load->view('mhs/footer');
    }

    function email() {
        $nim = $this->session->userdata('username');
        $nm = $this->mmr->get_nama($nim);
        $na['nama'] = $nm->nama;
        $na['nim'] = $nm->nim;
        $data['menu'] = $this->mmr->menu_surat($nim);
        $data['stat'] = $this->mmr->stat($nim);
        $em = $this->mmr->email_mhs($nim);
        $data['email'] = $em->email;
        if ($this->mmr->menu_profil($nim)) {
            $data['profil'] = $this->mmr->menu_profil($nim);
        } else {
            $data['profil'] = array();
        }
        if ($this->mmr->bimpro($nim)) {
            $data['bimpro'] = $this->mmr->bimpro($nim);
        } else {
            $data['bimpro'] = FALSE;
        }
        if ($this->mmr->bimtes($nim)) {
            $data['bimtes'] = $this->mmr->bimtes($nim);
        } else {
            $data['bimtes'] = FALSE;
        }
        $this->parser->parse('mhs/header', $na);
        $this->load->view('mhs/nav-bar');
        $this->load->view('mhs/sidebar', $data);
        $this->load->view('mhs/email', $data);
        $this->load->view('mhs/footer');
    }

    function emailNew() {
        $id = $this->session->userdata('username');
        $email = array(
            'email' => $this->input->post('email')
        );
        $this->mmr->updateEmail($id, $email);
        redirect('mahasiswa/email');
    }

    function download_saran() {
        $this->load->helper('download');
        $id = $this->uri->segment(3);
        $user = $this->session->userdata('username');
        $path = $this->mmr->get_link_dos($id, $user);
        $data = file_get_contents($path->full_path); // Read the file's contents
        $name = $path->file_name;
        force_download($name, $data);
//        print_r($path);
        $this->session->unset_userdata('jump');
    }

}

?>
